package com.flyu.mySocket;


import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpServerDome2 {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(6666);

        // 循环接收
        while (true){
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length);
            socket.receive(packet);
            // 断开连接 -- bye
            byte[] data = packet.getData();
            String receiveData = new String(data, 0, packet.getLength());
            System.out.println(receiveData);

            if (receiveData.equals("bye")){
                break;
            }
        }
        socket.close();
    }
}
